﻿@imports Library

@modelType Transaction

@Code
    ViewData("Title") = "Edit"
End Code

<div id="page">

    <div id="page_header" style="position:relative;">
        Edit Record (@Model.Owner)
    </div>

    <div id="page_body">
            
        <div class="IE_padding_hack">
	
            @Using Html.BeginForm("Edit", "Transaction", New With {.id = Model.Id}, FormMethod.Post)
                    
                @<input type="hidden" name="owner" value="@Model.owner" />
            
                @<table class="basic">
                    <tr>
                        <th>@Html.LabelExtension("recorddate", "Date", True)</th>
                        <td>@Html.TextBox("recorddate", model.RecordDate.ToString("yyyy-MM-dd"), New With {.id = "recorddate"})
                                <span class="red"> YYYY-MM-DD format.Required. </span></td>
                    </tr><tr>
                        <th>@Html.LabelExtension("name", "Name", True)</th>
                        <td>@Html.RadioButtonList("name", New SelectList(SharedCalls.TransactionNameList(Model.Owner), Model.Name), Nothing)</td>
                    </tr><tr>
                        <th>@Html.LabelExtension("remark", "Remark")</th>
                        <td>@Html.TextBoxFor(Function(model) model.Remark, New With{.class="inputText"})</td>
                    </tr><tr>
                        <th>@Html.LabelExtension("amount", "Amount", True)</th>
                        <td>@Html.TextBoxFor(Function(model) model.Amount, New With{.class="inputText"})</td>
                    </tr><tr>
                        <th>@Html.LabelExtension("recordtype", "Type", True)</th>
                        <td>@Html.RadioButtonList("recordtype", New SelectList(SharedCalls.TransactionTypeList(Model.Owner), Model.RecordType), Nothing)</td>
                    </tr><tr>
                        <th>@Html.LabelExtension("payer", "Payer", True)</th>
                        <td>@Html.RadioButtonList("payer", New SelectList(SharedCalls.TransactionPayerList(Model.Owner), Model.Payer), Nothing)</td>
                    </tr><tr>
                        <td colspan="2">
                            <input type="submit" id="submit" value="Save" /> or 
                            <a href="javascript:void(0)" onclick="DeleteRecord()">Delete</a> or 
                            @Html.ActionLink("Cancel", "Index", "AccountPeriod", New With{.owner = Model.Owner}, nothing)
                        </td>
                    </tr>
                </table>

            End Using

        </div>
                    
    </div>
        
</div>

@section Scripts

<script type="text/javascript">

    $(function () {
        var index = 0;
        if ('@Model.Owner' == "NICOLE") {
            index = 2;
        } else if ('@Model.Owner' == "VINCENT") {
            index = 1;
        };
        $("#global_nav li a").eq(index).addClass("selected");

        $(".radio-button-list").buttonset();

        if (index != 0) {
            $("#name").change(function () {
                $("#Remark").val($("#name :radio:checked").val());
            });
        }

        $("#recorddate").datepicker({
            dateFormat: 'yy-mm-dd',
            defaultDate: $("#recorddate").text()
        });

        $("#submit").click(function () {
            var amount = $("#Amount").val();
            if (IsNumeric(amount)) {
                $("#Amount").val(Math.round(amount));
                return true;
            } else {
                alert("amount is not a number!");
                return false;
            };
        });
    });

    function DeleteRecord() {
        if (confirm("Are you sure to delete this record?")) {
            window.location.href = '/transaction/delete?id=@Model.Id';
        }
    }
    
</script>

End Section



